package de.tabuma.wsdl2xform.controller;

import de.tabuma.lib.tabumacontroller;
import java.io.*;
import java.text.*;
import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;
import de.tabuma.wsdl2xform.view.*;
import java.util.Hashtable;

/**
 * This is the maincontroller class that is called from login.
 * It forwards to the controller depending on the main navigation
 * @see de.tabuma.wsdl2xform.login
 * @author $Author: alefen $
 * @version $Revision: 1.4.4.1 $
 * @since $Date: 2010/01/13 10:23:55 $
 */
public class controller extends tabumacontroller {

    private static Logger log =  Logger.getLogger(controller.class.getName());

    private de.tabuma.wsdl2xform.start.controller.controller startcontroller;
    private de.tabuma.wsdl2xform.xform.controller.controller createxformController;
    private de.tabuma.customer.controller.controller costumerlistController;
    private de.tabuma.adminarea.controller adminadminareaController;

    public controller(String servlet, Hashtable parameter) {
        super(servlet, parameter);
    }
    
    public void navigate(ServletContext context, HttpServletRequest request,HttpServletResponse response,PrintWriter out) {
        String mainnav = request.getParameter(constants.MAINNAV);
        if(mainnav==null) {
            mainnav = "" + constants.NAVID_START;
        }
        int mainnavInt = Integer.valueOf(mainnav);
        head head = new head(this.getServlet(), this.getParameter());
        head.processRequest(context, request, response,out);
        switch(mainnavInt) {
            case constants.NAVID_START:
                    this.startcontroller = new de.tabuma.wsdl2xform.start.controller.controller(this.getServlet(), this.getParameter());
                    log.fine("Giving the focus to the startcontroller.");
                    this.startcontroller.navigate(context, request, response,out);
                    break;
            case constants.NAVID_CREATEXFORM:
                    this.createxformController = new de.tabuma.wsdl2xform.xform.controller.controller(this.getServlet(), this.getParameter());
                    log.fine("Giving the focus to the createxformcontroller.");
                    this.createxformController.navigate(context, request, response,out);
                    break;
            case constants.NAVID_ORDERS:
                    Hashtable hash4 = this.getParameter();
                    hash4.put(constants.MAINNAV, ""+constants.NAVID_ORDERS);
                    de.tabuma.pm.shopping.ShoppingController ordercontroller = new de.tabuma.pm.shopping.ShoppingController(this.getServlet(), hash4, de.tabuma.pm.constants.SHOPPING_PARAM);
                    log.fine("Giving the focus to the ordercontroller.");
                    ordercontroller.navigate(context, request, response,out);
                    break;
            case constants.NAVID_COSTUMERLIST:
                    Hashtable tabCostum = (Hashtable) this.getParameter().clone();
                    tabCostum.put(constants.MAINNAV, "" + constants.NAVID_COSTUMERLIST);
                    this.costumerlistController = new de.tabuma.customer.controller.controller(this.getServlet(), tabCostum);
                    log.fine("Giving the focus to the costumerlistcontroller.");
                    this.costumerlistController.navigate(context, request, response,out);
                    break;
            case constants.NAVID_ADMINAREA:
                    Hashtable tabAdminArea = (Hashtable) this.getParameter().clone();
                    tabAdminArea.put(constants.MAINNAV, "" + constants.NAVID_ADMINAREA);
                    this.adminadminareaController = new de.tabuma.adminarea.controller(this.getServlet(), tabAdminArea);
                    log.fine("Giving the focus to the adminareacontroller.");
                    this.adminadminareaController.navigate(context, request, response, out);
                    break;
            case constants.NAVID_PROJECTS:
                    Hashtable tabProjects = (Hashtable) this.getParameter().clone();
                    tabProjects.put(constants.MAINNAV, "" + constants.NAVID_PROJECTS);
                    de.tabuma.pm.controller.controller projectController = new de.tabuma.pm.controller.controller(this.getServlet(), tabProjects);
                    log.fine("Giving the focus to the projectcontroller.");
                    projectController.navigate(context, request, response, out);
                    break;
        }
        bottom bottom = new bottom(this.getServlet(), this.getParameter());
        bottom.processRequest(context, request, response,out);
    }
}
